package com.example.adapter;

import java.util.List;

import com.example.domain.Food;
import com.example.mypro.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;

public class ExpandAdapter extends BaseExpandableListAdapter {
	private List<Food> list;
	private Context context;

	public ExpandAdapter(List<Food> list, Context context) {
		this.list = list;
		this.context = context;
	}

	@Override
	public Object getChild(int arg0, int arg1) {
		return list.get(arg0);
	}

	@Override
	public long getChildId(int arg0, int arg1) {
		return 0;
	}

	@Override
	public View getChildView(int arg0, int arg1, boolean arg2, View arg3,
			ViewGroup arg4) {
		View view = LayoutInflater.from(context).inflate(R.layout.food_item,
				null);
		TextView tv_name = (TextView) view.findViewById(R.id.fd_tv_name);
		TextView tv_address = (TextView) view.findViewById(R.id.fd_tv_address);
		TextView tv_district = (TextView) view
				.findViewById(R.id.fd_tv_district);
		TextView tv_distance = (TextView) view
				.findViewById(R.id.fd_tv_distance);
		TextView tv_tag = (TextView) view.findViewById(R.id.fd_tv_tag);
		TextView tv_price = (TextView) view.findViewById(R.id.fd_tv_price);
		TextView tv_telephone = (TextView) view
				.findViewById(R.id.fd_tv_telephone);
		TextView tv_type = (TextView) view.findViewById(R.id.fd_tv_type);
		TextView tv_linkname = (TextView) view
				.findViewById(R.id.fd_tv_linkname);
		TextView tv_linkurl = (TextView) view.findViewById(R.id.fd_tv_linkurl);
		TextView tag = (TextView) view.findViewById(R.id.tag);
		TextView linkurl = (TextView) view.findViewById(R.id.linkurl);
		TextView linkname = (TextView) view.findViewById(R.id.linkname);
		TextView price = (TextView) view.findViewById(R.id.price);
		TextView telephone = (TextView) view.findViewById(R.id.telephone);
		tv_name.setText(list.get(arg0).getname());
		tv_address.setText(list.get(arg0).getaddress());
		tv_district.setText(list.get(arg0).getdistrict());

		tv_distance.setText(String.valueOf(list.get(arg0).getDistance()));
		tv_type.setText(list.get(arg0).gettype());
		String test = list.get(arg0).gettag();
		if ("".equals(test) || "0".equals(test)) {
			tag.setVisibility(View.INVISIBLE);
		} else {
			tv_tag.setText(test);
		}

		test = list.get(arg0).gettelephone();
		if ("".equals(test) || "0".equals(test)) {
			telephone.setVisibility(View.INVISIBLE);
		} else {
			tv_telephone.setText(test);
		}

		test = list.get(arg0).getprice();
		if ("null".equals(test) || "0".equals(test)) {
			price.setVisibility(View.INVISIBLE);
		} else {
			tv_price.setText(test);
		}

		test = list.get(arg0).getLinkname();
		if ("0".equals(test)) {
			linkname.setVisibility(View.INVISIBLE);
		} else {
			tv_linkname.setText(test);
		}

		test = list.get(arg0).getLinkurl();
		if ("0".equals(test)) {
			linkurl.setVisibility(View.INVISIBLE);
		} else {
			tv_linkurl.setText(test);
		}
		return view;
	}

	@Override
	public int getChildrenCount(int arg0) {
		// TODO Auto-generated method stub
		return 1;
	}

	@Override
	public Object getGroup(int arg0) {
		return list.get(arg0);
	}

	@Override
	public int getGroupCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public long getGroupId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public View getGroupView(int arg0, boolean arg1, View arg2, ViewGroup arg3) {
		View view = LayoutInflater.from(context).inflate(R.layout.xw_lv_item,
				null);
		TextView tv = (TextView) view.findViewById(R.id.xw_lv_title);
		tv.setText(list.get(arg0).getname());
		return view;
	}

	@Override
	public boolean hasStableIds() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean isChildSelectable(int arg0, int arg1) {
		return true;
	}

}
